package git.soulbgm.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * 远程参数配置
 *
 * @author SoulBGM
 * @date 2022/10/09 18:12
 */
@Configuration
@ConfigurationProperties(prefix = "remote.param", ignoreUnknownFields = false)
public class RemoteParamConfig {

    /**
     * 获取配置参数的服务地址和端口 多个以,隔开
     */
    private List<String> servers;

    /**
     * 连接超时(单位:毫秒)
     */
    private int connectTimeout = 5000;

    /**
     * 读取超时(单位:毫秒)
     */
    private int readTimeout = 20000;

    @Bean
    public RestTemplate restTemplate() {
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        factory.setConnectTimeout(connectTimeout);
        factory.setReadTimeout(readTimeout);
        return new RestTemplate(factory);
    }

    public List<String> getServers() {
        return servers;
    }

    public void setServers(List<String> servers) {
        this.servers = servers;
    }

    public int getConnectTimeout() {
        return connectTimeout;
    }

    public void setConnectTimeout(int connectTimeout) {
        this.connectTimeout = connectTimeout;
    }

    public int getReadTimeout() {
        return readTimeout;
    }

    public void setReadTimeout(int readTimeout) {
        this.readTimeout = readTimeout;
    }
}
